 

package com.zdkj.subway.stm.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.constant.CommonConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.stm.dto.in.QueryContionDTO;
import com.zdkj.subway.stm.entity.SwStPackageTailboxManage;
import com.zdkj.subway.stm.entity.SwStTvmCheckDetail;
import com.zdkj.subway.stm.service.SwStPackageTailboxManageService;
import com.zdkj.subway.stm.util.BeanUtilsStm;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 库包/尾箱管理主表
 *
 * @author chenbo
 * @date 2020-01-31 18:10:27
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstpackagetailboxmanage" )
@Api(value = "swstpackagetailboxmanage", tags = "库包/尾箱管理主表管理")
public class SwStPackageTailboxManageController {

    private final  SwStPackageTailboxManageService swStPackageTailboxManageService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStPackageTailboxManage 库包/尾箱管理主表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStPackageTailboxManagePage(Page page, SwStPackageTailboxManage swStPackageTailboxManage, QueryContionDTO queryContionDTO) {
        QueryWrapper<SwStPackageTailboxManage> query = BeanUtilsStm.addTimeContiontion(swStPackageTailboxManage, queryContionDTO, "HAND_TIME");
        return R.ok(swStPackageTailboxManageService.page(page,query));
    }


    /**
     * 通过id查询库包/尾箱管理主表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swStPackageTailboxManageService.getById(id));
    }

    /**
     * 新增库包/尾箱管理主表
     * @param swStPackageTailboxManage 库包/尾箱管理主表
     * @return R
     */
    @ApiOperation(value = "新增库包/尾箱管理主表", notes = "新增库包/尾箱管理主表")
    @SysLog("新增库包/尾箱管理主表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stm_sw_st_package_tailbox_manage_add')" )
    public R save(@RequestBody SwStPackageTailboxManage swStPackageTailboxManage) {
        SwStPackageTailboxManage defaultObj = ObjectUtils.getDefaultObj(SwStPackageTailboxManage.class);
        BeanUtil.copyProperties(defaultObj, swStPackageTailboxManage, CopyOptions.create().setIgnoreNullValue(true));
        return R.ok(swStPackageTailboxManageService.save(swStPackageTailboxManage));
    }

    /**
     * 修改库包/尾箱管理主表
     * @param swStPackageTailboxManage 库包/尾箱管理主表
     * @return R
     */
    @ApiOperation(value = "修改库包/尾箱管理主表", notes = "修改库包/尾箱管理主表")
    @SysLog("修改库包/尾箱管理主表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stm_sw_st_package_tailbox_manage_edit')" )
    public R updateById(@RequestBody SwStPackageTailboxManage swStPackageTailboxManage) {
        return R.ok(swStPackageTailboxManageService.updateById(swStPackageTailboxManage));
    }

    /**
     * 通过id删除库包/尾箱管理主表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除库包/尾箱管理主表", notes = "通过id删除库包/尾箱管理主表")
    @SysLog("通过id删除库包/尾箱管理主表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stm_sw_st_package_tailbox_manage_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swStPackageTailboxManageService.removeById(id));
    }

}
